module(
    name = "cpptrace",
)

bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_foreign_cc", version = "0.11.1")
bazel_dep(name = "zstd", version = "1.5.6")
bazel_dep(name = "zlib", version = "1.3.1")
bazel_dep(name = "xz", version = "5.4.5.bcr.2")
bazel_dep(name = "toolchains_llvm", version = "1.1.2")

# Configure and register the toolchain.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)

llvm.toolchain(
    llvm_versions = {
        "": "18.1.8",
    },
    sha256 = {
        "": "54ec30358afcc9fb8aa74307db3046f5187f9fb89fb37064cdde906e062ebf36",
    },
    strip_prefix = {
        "": "clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04",
    },
    urls = {
        "": ["https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz"],
    },
)

use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all", dev_dependency = True)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "libdwarf",
    build_file_content =
        """
package(default_visibility = ["//visibility:public"])
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

filegroup(
    name = "sources",
    srcs = glob(["**/*"]),
)
cmake(
    name = "libdwarf",
    build_args = ["-j12"],
    lib_source = ":sources",
    out_static_libs =  ["libdwarf.a"],
    copts = ["-Wall", "-Werror"],
    deps = [
        "@zstd",
        "@zlib"
    ]
)
""",
    sha256 = "4ab8ae7b4b7aa42453725054b348f4fdb2460d5ba644199a1305311c718ff416",
    strip_prefix = "libdwarf-code-0.10.1",
    url = "https://github.com/davea42/libdwarf-code/archive/refs/tags/v0.10.1.tar.gz",
)



http_archive(
    name = "libunwind",
    build_file_content =
        """
package(default_visibility = ["//visibility:public"])
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
    name = "sources",
    srcs = glob(["**/*"]),
)
configure_make(
    name = "libunwind",
    args = ["-j12"],
    autoreconf = True,
    configure_in_place = True,
    autoreconf_options = [
        "-i",
    ],
    lib_source = ":sources",
    out_static_libs =  [
        "libunwind.a",
        "libunwind-coredump.a",
        "libunwind-ptrace.a",
        "libunwind-x86_64.a",
        "libunwind-generic.a",
        "libunwind-setjmp.a"
    ],
    deps = [
        "@xz//:lzma"
    ]
)
""",
    sha256 = "38833b7b1582db7d76485a62a213706c9252b3dab7380069fea5824e823d8e41",
    strip_prefix = "libunwind-1.8.1",
    url = "https://github.com/libunwind/libunwind/archive/refs/tags/v1.8.1.tar.gz",
)

